package com.year_23.may;

import java.util.Arrays;

/**
 * @author: jsh
 * @create: 2023/5/25 22:07
 * @Description:2451. 差值数组不同的字符串
 * @FileName: Day25
 * @History:
 * @自定义内容：
 */
public class Day25 {
    public String oddString(String[] words) {
        int[] diff0 = getDiff(words[0]);
        int[] diff1 = getDiff(words[1]);
        if (Arrays.equals(diff0,diff1)) {
            for (int i = 2; i < words.length; i++) {
                if (!Arrays.equals(getDiff(words[i]), diff0)){
                    return words[i];
                }
            }
        }
        return Arrays.equals(diff0, getDiff(words[2]))? words[1] : words[0];
    }

    private int[] getDiff(String word) {
        int[] diff = new int[word.length()-1];
        for (int i = 0; i + 1< word.length(); i++) {
            diff[i] = word.charAt(i+1) - word.charAt(i);
        }
        return diff;
    }
}
